package com.web.java0328springboot.controller;

import com.web.java0328springboot.entity.PageVO;
import com.web.java0328springboot.entity.ResponseResult;
import com.web.java0328springboot.entity.Student;
import com.web.java0328springboot.service.StudentService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lenovo
 * @Description
 * @Date2025/3/28 下午3:55
 */
@CrossOrigin
@RestController
public class StudentController {
//    @Resource
//    private StudentService studentService;
//    @RequestMapping("/findStudentPage")
//    public ResponseResult findStudentPage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
//                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
//        PageVO page = studentService.getStudentPage(current, pageSize);
//        return new ResponseResult(200,"OK",page);
//    }
//
//    @RequestMapping("insertStudent")
//    public ResponseResult addStudent(Student student){
//        studentService.save(student);
//        return new ResponseResult(200,"OK",null);
//    }
//
//    @RequestMapping("updateStudent")
//    public ResponseResult updateStudent(Student student){
//        studentService.updateById(student);
//        return new ResponseResult(200,"OK",null);
//    }
//
//    @RequestMapping("deleteStudent")
////    public ResponseResult deleteStudent(Integer id){
////        studentService.removeById(id);
////        return new ResponseResult(200,"OK",null);
//    }

    @Resource
    private StudentService studentService;
    @RequestMapping(value = "/findStudentPage",method = RequestMethod.GET)
    public ResponseResult findStudentPage(@RequestParam(name = "current",required = false,defaultValue = "1")int current,
                                          @RequestParam(name = "pageSize",required = false,defaultValue = "10")int pageSize){
        PageVO page = studentService.getStudentPage(current, pageSize);
        return new ResponseResult(200,"OK",page);
    }

    @RequestMapping(value = "student",method = RequestMethod.POST)
    public ResponseResult addStudent(Student student){
        studentService.save(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping(value = "student",method = RequestMethod.PUT)
    public ResponseResult updateStudent(Student student){
        studentService.updateById(student);
        return new ResponseResult(200,"OK",null);
    }

    @RequestMapping(value = "student/{id}",method = RequestMethod.DELETE)
    public ResponseResult deleteStudent(@PathVariable Integer id){
        studentService.removeById(id);
        return new ResponseResult(200,"OK",null);
    }

}
